package epin.fujiajun.sort.primary;

import epin.fujiajun.data.Array;
import epin.fujiajun.data.array.Number;
import epin.fujiajun.sort.ArraySortBase;


/**
 * Created by DELL on 2017/8/15.
 */
public class Shell extends ArraySortBase {

    @Override
    public void sort(Array[] a) {
        int N = a.length;
        int h = 1;

        while (h < N / 3){
            h = 3 * h + 1;
        }

        while (h >= 1){
            for (int i = h; i < N; i++){
                for (int j = i; j >= h && less(a[j], a[j-h]); j -= h){
                    exChange(a, j, j-h);
                }
            }
            h = h / 3;
        }
    }

    public static void main(String[] args){
        new Shell().main(Number.createArray(100, 1000));
    }
}
